package com.kkb.controller;

import com.kkb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@RequestMapping("User")
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/add.do",method = RequestMethod.GET)
    public ModelAndView add(){
        System.out.println("这个是控制层的add方法");
        ModelAndView mv = new ModelAndView();
        userService.add();  // 调用UserService的方法
        mv.setViewName("User/add");  // 相当于转发 物理地址
        return mv;
    }

    @RequestMapping(value = "/update.do",method = RequestMethod.POST)
    public ModelAndView update(){
       // System.out.println("这个是控制层的update方法");
        ModelAndView mv = new ModelAndView();
       // userService.add();  // 调用UserService的方法
        mv.setViewName("User/update");  // 相当于转发 物理地址
        return mv;
    }

    @RequestMapping("/hello.do")
    public ModelAndView hello(){
        System.out.println("这个是控制层的add方法");
        userService.add();  // 调用UserService的方法
        ModelAndView mv = new ModelAndView();
        mv.addObject("uname","阿柴"); // 相当于setattitude
        mv.setViewName("index");  // 相当于转发
        return mv;
    }
}
